package com.tools.app.task;

import com.hm.base.android.mob.AMApplication;
import com.hm.base.android.mob.service.IService;
import com.hm.base.android.mob.task.AMServiceWrapper;
import com.hm.base.android.mob.task.AsyncOperation;
import com.hm.base.android.mob.task.IResultReceiver;
import com.hm.base.android.mob.task.mark.ResultReceiverTaskMark;
import com.tools.app.AppConstant;
import com.tools.app.task.mark.SubmitReferrerTaskMark;
import com.tools.app.tracker.SubmitReferrerTracker;

/**
 * Created by ChenLi on 2017/12/13.
 */

public class AppServiceWrapper extends AMServiceWrapper {

    public AppServiceWrapper(AMApplication imContext, IService service) {
        super(imContext, service);
    }

    @Override
    public AsyncOperation executeOneOfMultipleTask(IResultReceiver resultReceiver, ResultReceiverTaskMark taskMark, Object attach) {
        return null;
    }

    /**
     * GP推广渠道追踪上报
     *
     * @param resultReceiver
     * @param taskMark
     * @param referrer
     * @return
     */
    public AsyncOperation submitReferrer(IResultReceiver resultReceiver, SubmitReferrerTaskMark taskMark, String referrer, long time) {
        AsyncOperation operation = null;
        try {
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
            } else {
                operation = wraperOperation(new SubmitReferrerTracker(imContext, resultReceiver), taskMark, AppConstant.SERVICE_MARK_SUBMITREFERRER, null);
                operation.excuteOperate(service, referrer, time);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return operation;
    }

}
